package edu.del.teamknowledgebase.common.exception;

import edu.del.teamknowledgebase.common.result.ApiCode;
import edu.del.teamknowledgebase.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice(basePackages = "edu.del.teamknowledgebase.web.controller")
public class GlobalExceptionAdvice {

    @ExceptionHandler(GlobalException.class)
    public Result<?> handleGlobalException(GlobalException e) {
        log.error("全局异常：{}", e.getMessage());
        return Result.fail(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result<?> handleException(Exception e) {
        log.error("服务器内部错误：{}", e.getMessage());
        return Result.fail(ApiCode.INTERNAL_ERROR);
    }
}
